package com.gnerv.pabu.plugin.mybatis.plus;

import com.gnerv.pabu.plugin.utils.ClassFileUtils;
import com.gnerv.pabu.plugin.utils.TemMapUtils;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

@Slf4j
public class CreateServiceClass extends AnAction {

    public CreateServiceClass(@Nls(capitalization = Nls.Capitalization.Title) @Nullable String text) {
        super(text);
    }

    @Override
    public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
        VirtualFile virtualFile = anActionEvent.getData(CommonDataKeys.VIRTUAL_FILE);
        String name = Messages.showInputDialog("类名", "设置类名", Messages.getQuestionIcon());
        Map map = TemMapUtils.getMap(anActionEvent, name);
        ClassFileUtils.writeStringToFile(virtualFile.getCanonicalPath(), PrefixSuffix.service(name), 1, map);
    }

}
